using System;
using System.Collections.Generic;

namespace SCG.General
{
    public class ImpulseActions
    {
        //constructor
        public ImpulseActions(int maxImpulses)
        {
            if (maxImpulses < 2)
                throw new ArgumentException("maxImpulses must be greater than one");

            _impulseCount = maxImpulses;
            _actions.Clear();
            for (int m = 1; m <= maxImpulses; m++)
            {
                string s = "";
                decimal add = (decimal)m / (decimal)maxImpulses;
                decimal sum = 0;
                for (int e = 1; e <= maxImpulses; e++)
                {
                    sum += add;
                    if (sum >= 1)
                    {
                        s += "1";
                        sum -= 1;
                    }
                    else
                        s += "0";
                }
                _actions.Add(s);
            }
        }

        //Can an actor with the specified movement rating act on a given impulse?
        //Movement is assumed to be inclusive of upper bound - (i.e. 1-20 for 20 max impulses)
        public bool CanAct(int movement, int impulse)
        {
            if (movement <= 0)
                return false;
            impulse = impulse % _impulseCount;           
            string s = _actions[movement - 1];
            return s[impulse] == '1';
        }

        //private members
        private int _impulseCount = 1;
        private List<string> _actions = new List<string>();
    }
}
